package com.study.demo.dao;

import com.study.demo.entity.User;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created on 2019/9/19.
 *
 * @author Grak
 * @since 1.0
 */
@Component
public class UserRepository {

    static List<User> users = new ArrayList<>();

    static {
        for(int i = 0;i<10;i++){
            User user = new User();
            user.setId(i * 111 + "");
            user.setUsername("李白" + i);
            user.setPassword("123" + i);
            users.add(user);
        }
    }

    public User findByUsername(User user){
        for(User user1 : users){
            if(user1.getUsername().equals(user.getUsername())){
                return user;
            }
        }
        return null;
    }

    public List<User> findAll(){
        return users;
    }

    public User findUserById(String userId) {
        for(User user1 : users){
            if(user1.getId().equals(userId)){
                return user1;
            }
        }
        return null;
    }
}
